package com.example.jsd2205.vx.emos.service.impl;


import com.example.jsd2205.vx.emos.db.dao.MessageDao;
import com.example.jsd2205.vx.emos.db.dao.MessageRefDao;
import com.example.jsd2205.vx.emos.db.pojo.MessageEntity;
import com.example.jsd2205.vx.emos.db.pojo.MessageRefEntity;
import com.example.jsd2205.vx.emos.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
/*
 * @author admin 兰
 * */
@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageDao messageDao;

    @Autowired
    private MessageRefDao messageRefDao;
    //插入消息记录
    @Override
    public String insertMessage(MessageEntity entity) {
        String id=messageDao.insert(entity);
        return id;
    }
    //分页查询结果
    @Override
    public List<HashMap> searchMessageByPage(int userId, long start, int length) {
        List<HashMap> list=messageDao.searchMessageByPage(userId,start,length);
        return list;
    }
    //根据ID查询数据
    @Override
    public HashMap searchMessageById(String id) {
        HashMap map=messageDao.searchMessageById(id);
        return map;
    }
    //向REF集合插入数据
    @Override
    public String insertRef(MessageRefEntity entity) {
        String id=messageRefDao.insert(entity);
        return id;
    }
    //查询未读消息的数量
    @Override
    public long searchUnreadCount(int userId) {
        long count=messageRefDao.searchUnreadCount(userId);
        return count;
    }

    @Override
    public long searchLastCount(int userId) {
        long count=messageRefDao.searchLastCount(userId);
        return count;
    }

    @Override
    public long updateUnreadMessage(String id) {
        long rows=messageRefDao.updateUnreadMessage(id);
        return rows;
    }

    @Override
    public long deleteMessageRefById(String id) {
        long rows=messageRefDao.deleteMessageRefById(id);
        return rows;
    }

    @Override
    public long deleteUserMessageRef(int userId) {
        long rows=messageRefDao.deleteUserMessageRef(userId);
        return rows;
    }
}
